from django.db import models
from django.utils import timezone


class AccountInfo(models.Model):
    id = models.AutoField(primary_key=True)
    nick_name = models.CharField(max_length=50, blank=False)
    mobile_phone = models.CharField(max_length=20)
    password = models.CharField(max_length=32)
    is_superuser = models.SmallIntegerField(default=0, verbose_name="是否超级用户，1为最高权限，2为普通管理员")
    is_staff = models.SmallIntegerField(default=0, verbose_name="是否工作人员")
    is_active = models.SmallIntegerField(default=0, verbose_name="账号活动状态")
    is_allow_post = models.SmallIntegerField(default=0, verbose_name="是否禁言")
    avatar = models.CharField(max_length=150, verbose_name="头像OSS-URL")
    slogan = models.CharField(max_length=50, verbose_name="个性签名", default='')
    sex = models.SmallIntegerField(default=0, verbose_name="性别")
    location = models.CharField(max_length=100, verbose_name="位置信息", default='')
    province_code = models.CharField(max_length=10, default='', verbose_name="前端使用--省份的code")
    city_code = models.CharField(max_length=10, default='', verbose_name="前端使用--市的code")
    role_id = models.IntegerField(default=1, verbose_name="对应的角色ID")

    qualifications = models.CharField(max_length=50, verbose_name="资质信息", default='')
    company = models.CharField(max_length=50, verbose_name="所在公司名称", default='')
    #register_tag = models.SmallIntegerField(default=0, verbose_name="用户注册来源")

    last_login = models.DateTimeField('最近一次登录时间', default=timezone.now)
    create_time = models.DateTimeField('注册时间', default=timezone.now)

    def __str__(self):
        return self.nick_name + self.mobile_phone

    def __repr__(self):
        return self.nick_name + self.mobile_phone


class AccountFollow(models.Model):
    id = models.AutoField(primary_key=True)
    follow_account_id = models.IntegerField('关注的用户ID')
    created_by_id = models.IntegerField('用户ID')

    created_on = models.DateTimeField('创建时间', default=timezone.now)


class Role(models.Model):
    """
        角色权限表
    """
    id = models.AutoField(primary_key=True)
    role_name = models.CharField(max_length=30, blank=False, verbose_name='角色名')
    module_list = models.CharField(max_length=255, blank=False, verbose_name='拥有的权限列表')
    enable = models.SmallIntegerField(default=0, verbose_name="是否启用，0为启用")
    is_superuser = models.SmallIntegerField(default=0, verbose_name="关联到Account表is_superuser字段")
    created_on = models.DateTimeField('创建时间', default=timezone.now)

    def __str__(self):
        return self.role_name


class ModuleType(models.Model):
    """
        后台功能所有模块
    """
    id = models.AutoField(primary_key=True)
    module_name = models.CharField(max_length=20, blank=False, verbose_name='模块名称')
    parent_id = models.IntegerField(default=0)
    is_show = models.SmallIntegerField(default=0, verbose_name='模块是否前端显示,1为不显示')

    def __str__(self):
        return self.module_name


class ActivityRegisterInfo(models.Model):
    """
        活动注册信息表
    """
    id = models.AutoField(primary_key=True)
    account_id = models.IntegerField(null=False, verbose_name="用户ID")
    mobile_phone = models.CharField(max_length=20, default='')
    nick_name = models.CharField(max_length=50, blank=False, default='')
    location = models.CharField(max_length=100, verbose_name="位置信息", default='')
    province_code = models.CharField(max_length=10, default='', verbose_name="前端使用--省份的code")
    city_code = models.CharField(max_length=10, default='', verbose_name="前端使用--市的code")
    company = models.CharField(max_length=50, verbose_name="所在公司名称", default='')
    create_time = models.DateTimeField('注册时间', default=timezone.now)
